﻿using Newtonsoft.Json;
using Serilog.Core;
using SKIT.FlurlHttpClient.Wechat.Api;
using SKIT.FlurlHttpClient.Wechat.Api.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.WxaApiUserLogSearchResponse.Types.Data.Types.RealtimeLog.Types;

namespace RabitMaclient
{
    public class WxSend
    {

        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="token"></param>
        public static void SendMsg(string token , WechatApiClientOptions  options, String json,Logger log)
        {

            CgibinMessageTemplateSendRequest tplr = JsonConvert.DeserializeObject<CgibinMessageTemplateSendRequest>(json);

            tplr.AccessToken = token;
            //tplr.Url = "";

            var client = new WechatApiClient(options);
            
             client.ExecuteCgibinMessageTemplateSendAsync(tplr).ContinueWith(res => {

              //   global::System.Console.WriteLine("发送");
                 var msg = res.Result.ErrorMessage;
                // global::System.Console.WriteLine(msg);
                 log.Write(Serilog.Events.LogEventLevel.Warning, json + "=>" +msg );
                 
                 
           }); 


        }

    }
}
